Exercise 1: Solving Hermite equations

Without using a CAS system, compute the generic values of the four unknown a, b, c, d when one know the values of $P_{0}$, $P_{1}$, $P_0^t$ and $P_1^t$.


In [ ]:


In [40]:
# Imports
import numpy

# Assumption about points and tangents
p0   = numpy.array([0, 0])
p0_t = numpy.array([-2, 1])
p1   = numpy.array([1, 0.7])
p1_t = numpy.array([1.5, -3])

# Compute coefficients
# a = 2 * p0 - 2 * p1 + p0_t + p1_t
# b = -3 * p0 + 3 * p1 - 2 * p0_t - p1_t
# c = p0_t
# d = p0

# We do this by hand, as stated in the exercise
p0_times_two = [ 2 * p0[0], 2 * p0[1] ]
p0_times_two_cas = 2 * p0
assert numpy.array_equal(p0_times_two, p0_times_two_cas)
print ("2 * p0 = [2 * p0.x]\n"
       "         [2 * p0.y]\n")

p1_times_two = [ 2 * p1[0], 2 * p1[1] ]
p1_times_two_cas = 2 * p1
assert numpy.array_equal(p1_times_two, p1_times_two_cas)
print ("2 * p1 = [2 * p1.x]\n"
       "         [2 * p1.y]\n")

# p0_times_two - p1_times_two
p0_minus_p1 = [ 
    p0_times_two[0] - p1_times_two[0],
    p0_times_two[1] - p1_times_two[1]
]
p0_minus_p1_cas = 2 * p0 - 2 * p1
assert numpy.array_equal(p0_minus_p1, p0_minus_p1_cas)

# p0_minus_p1 + p0_t
p0_minus_p1_plus_p0_t = [
    p0_minus_p1[0] + p0_t[0],
    p0_minus_p1[1] + p0_t[1],
]
p0_minus_p1_plus_p0_t_cas = 2 * p0 - 2 * p1 + p0_t
assert numpy.array_equal(p0_minus_p1_plus_p0_t, p0_minus_p1_plus_p0_t_cas)

# p0_minus_p1_plus_p0_t + p1_t
p0_minus_p1_plus_p0_t_plus_p1_t = [
    p0_minus_p1_plus_p0_t[0] + p1_t[0],
    p0_minus_p1_plus_p0_t[1] + p1_t[1],
]
p0_minus_p1_plus_p0_t_plus_p1_t_cas = 2 * p0 - 2 * p1 + p0_t + p1_t
assert numpy.array_equal(p0_minus_p1_plus_p0_t_plus_p1_t, p0_minus_p1_plus_p0_t_plus_p1_t_cas)

a = p0_minus_p1_plus_p0_t_plus_p1_t
a_cas = 2 * p0 - 2 * p1 + p0_t + p1_t
assert numpy.array_equal(a, a_cas)

b = -3 * p0 + 3 * p1 - 2 * p0_t - p1_t
c = p0_t
d = p0

print ('a: {0}\n'
       'b: {1}\n'
       'c: {2}\n'
       'd: {3}'
       ).format(
           a, b, c, d
        )


2 * p0 = [2 * p0.x]
         [2 * p0.y]

2 * p1 = [2 * p1.x]
         [2 * p1.y]

a: [-2.5, -3.3999999999999999]
b: [ 5.5  3.1]
c: [-2  1]
d: [0 0]

In [18]:
i

In [ ]: